package com.java123.t9.demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class DemoStream {

	public static void main(String[] args) {
		File file = new File("C:" + File.separator + "Users" + File.separator + "kevin" + File.separator + "Desktop"
				+ File.separator + "test1.txt");
		if (file.exists()) {
			try {
				InputStream in = new FileInputStream(file);
				
				File test2 = new File("C:" + File.separator + "Users" + File.separator + "kevin" + File.separator + "Desktop"
				+ File.separator + "test2.txt");
				if(!test2.exists()){
					test2.createNewFile();
				}
				OutputStream out = new FileOutputStream(test2);
				
				// 申明一个水桶
				byte[] bytes = new byte[1024];
				int len;
				while ((len = in.read(bytes)) > 0) {
					out.write(bytes, 0, len);
				}
				out.flush();
				in.close();
				out.close();
				
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
	}

}
